package com.zimin.mapper.injector;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zimin.common.utils.BeanUtils;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * @author zimin
 * @since 2022/1/24 5:02 下午
 */
public class InjectServiceImpl<M extends InjectBaseMapper<T>, T> extends ServiceImpl<M, T> {

    @Deprecated
    public <V> List<V> list(Wrapper<T> queryWrapper, Class<V> v) {
        List<T> ts = super.list(queryWrapper);
        return BeanUtils.listEntityToView(ts, v);
    }

    public <V> List<V> list(LambdaQueryChainWrapper<T> lambdaQueryChainWrapper, Class<V> v) {
        List<T> ts = lambdaQueryChainWrapper.list();
        return BeanUtils.listEntityToView(ts, v);
    }


    public <V> List<V> listByIds(Collection<? extends Serializable> idList, Class<V> v) {
        List<T> ts = super.listByIds(idList);
        return BeanUtils.listEntityToView(ts, v);
    }

    @Deprecated
    public <V> V getOne(Wrapper<T> queryWrapper, Class<V> v) {
        T t = super.getOne(queryWrapper);
        return BeanUtils.coverClass(t, v);
    }

    public <V> V getOne(LambdaQueryChainWrapper<T> lambdaQueryChainWrapper, Class<V> v) {
        T t = lambdaQueryChainWrapper.one();
        return BeanUtils.coverClass(t, v);
    }

    public <V> V getById(Serializable id, Class<V> v) {
        T t = getById(id);
        return BeanUtils.coverClass(t, v);
    }



}
